#include <stdio.h> 
#include <stdlib.h> 
#include <fcntl.h> /* open, close */
#include <unistd.h>

#include "contexts.h"
#include "posets.h"
#include "algo1110.h"

#include "debug.h"

static Context context;

void
proc(void)
{
  Poset *p,*q;

  p = algo1110(&context);
  q = poset_tsort_of(p);

  poset_print_latdraw(q);
  
  poset_free(p);
  poset_free(q);
}

int
main(int argc, char * argv[]){

  int fd = STDIN_FILENO; /**< input file descriptor */ 

  if(argc > 2)
    exit(EXIT_FAILURE);
  
  if(argc == 2)
    {
      if( (fd =open(argv[1],O_RDONLY)) < 0)
	exit(EXIT_FAILURE);
    }

  ctx_init(&context,0,0);
  ctx_parse(&context,fd);

  proc();

  exit(EXIT_SUCCESS);
}

